/*
   Copyright (c) 2010 Bryce Alcock

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.com

 */

/*
 * NetworkTest.java
 *
 * Created on Oct 6, 2010, 11:00:06 AM
 */

package com.ecocrypt.network.gui;

import java.net.Socket;

/**
 *
 * @author Bryce.Alcock
 */
public class NetworkTest extends javax.swing.JFrame {

    Socket s;
    /** Creates new form NetworkTest */
    public NetworkTest() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        socketIPAddress = new javax.swing.JComboBox();
        socketPort = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        sendString = new javax.swing.JButton();
        resetSocketButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        socketIPAddress.setEditable(true);
        socketIPAddress.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        getContentPane().add(socketIPAddress, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 40, 110, -1));

        socketPort.setEditable(true);
        socketPort.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        getContentPane().add(socketPort, new org.netbeans.lib.awtextra.AbsoluteConstraints(205, 40, 112, -1));

        jLabel1.setText("Remote IP Address/Host");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 16, -1, -1));

        jLabel2.setText("Remote port");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(205, 16, -1, -1));

        jScrollPane1.setViewportView(jTextPane1);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 86, 534, 100));

        jScrollPane2.setViewportView(jTextPane2);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 276, 534, 209));

        sendString.setText("Send String");
        sendString.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendStringActionPerformed(evt);
            }
        });
        getContentPane().add(sendString, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 203, 88, -1));

        resetSocketButton.setText("Reset Socket");
        resetSocketButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetSocketButtonActionPerformed(evt);
            }
        });
        getContentPane().add(resetSocketButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(335, 39, -1, -1));

        jLabel3.setText("Status");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(504, 45, -1, -1));

        jLabel4.setText("bytes sent:");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 203, -1, -1));

        jLabel5.setText("bytes recvd:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(118, 236, -1, -1));

        jTextField1.setText("jTextField1");
        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(214, 198, 102, -1));

        jTextField2.setText("jTextField2");
        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(214, 231, 102, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void resetSocketButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetSocketButtonActionPerformed

        String ipAddress = socketIPAddress.getSelectedItem().toString();
        int port = Integer.parseInt(socketPort.getSelectedItem().toString());

        try{
            if(s!=null){
                if(s.isBound()){
                    s.close();
                }
            }
            s = null;
        }catch (Throwable t){
            //
            t.printStackTrace();
        }
        if(ipAddress!=null){
//           Socket s = new Socket(ipAddress, port);
        }

        System.out.println("Reset Socket Called...");

        // TODO add your handling code here:
    }//GEN-LAST:event_resetSocketButtonActionPerformed

    private void sendStringActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendStringActionPerformed

        System.out.println("Send Data...");
        
        // TODO add your handling code here:
    }//GEN-LAST:event_sendStringActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NetworkTest().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JButton resetSocketButton;
    private javax.swing.JButton sendString;
    private javax.swing.JComboBox socketIPAddress;
    private javax.swing.JComboBox socketPort;
    // End of variables declaration//GEN-END:variables

}
